package com.mgq.java8.option.c2;

import java.util.Optional;

public class Shopper {

  private Trolley trolley;

  public Trolley getTrolley(){

    return trolley;

  }

  public String result(Shopper shopper){

    return Optional.ofNullable(shopper)
            .map(Shopper::getTrolley)

            .map(Trolley::getChestnut)

            .map(Chestnut::getName)

            .orElse("获取失败了");

  }

  public static void main(String[] args) {
    Shopper shopper = new Shopper();
    System.out.println(shopper.result(shopper));
  }
}

